home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The AGA Experience 3
/
AGA Experience Volume 3 (1997)(NFA - SAdENESS)[!].iso
/
software
/
utilities
/
graphics
/
raylab
/
source
/
camera.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-09
|
2KB
|
60 lines
/*
name: camera.c
Camera-routines
---------------
These routines are used for handling the camera (positioning,
rotation etc).
This source-code is part of the RayLab 1.1 package, and it is provided
for your compiling pleasure. You may use it, change it, re-compile it
etc., as long as nobody else but you receive the changes/compilations
that you have made!
You may not use any part(s) of this source-code for your own productions
without the permission from the author of RayLab. Please read the legal
information found in the users documentation for RayLab for more details.
*/
#include "defs.h"
void CreateCamera(CAMERA *Camera, POINT *Loc, POINT *VP, VECTOR *Asp)
{
double costheta;
VECTOR D,R,U;
D.x=(VP->x-Loc->x); /* Calculate direction-vector */
D.y=(VP->y-Loc->y);
D.z=(VP->z-Loc->z);
NormalizeVector(&D,&D); /* Make direction-vector unit-sized */
/* This is important for the calcu- */
/* lations of the up- and right- */
/* vectors! */
costheta=cos(asin(D.z)); /* Calculate right-vector */
if(fabs(costheta)>0.0) {
R.x=D.y/costheta; /* "/cos(theta)" => |R| = 1 */
R.y=-(D.x/costheta);
R.z=0.0;
}
else {
R.x=1.0; R.y=0.0; R.z=0.0; /* (looking straight up or down) */
}
CrossProduct(&U,&R,&D); /* U = R x D */
Camera->Location=*Loc; /* Declare camera location */
Camera->ViewPoint=*VP; /* Declare view-point */
Camera->Aspect=*Asp; /* Declare camera aspect */
Camera->Direction=D; /* Declare camera direction */
Camera->Up=U; /* Declare camera up-vector */
Camera->Right=R; /* Declare camera right-vector */
}